package example;

import java.util.ArrayList;
import java.util.List;

/**
 * 被观察者
 * @Author itmei
 * @Package org.example
 * @Date 2025/8/4 11:03
 */
public class Newspaperimpl implements Newspaper {
   List<Subscriber> subscribers=new ArrayList<>();
    @Override
    public void addSubscriber(Subscriber subscriber) {
        subscribers.add(subscriber);
    }

    @Override
    public void removeSubscriber(Subscriber subscriber) {
        subscribers.remove(subscriber);
    }

    @Override
    public void notifySubscriber(String message) {
        for(Subscriber subscriber:subscribers){
            subscriber.update(message);
        }
    }
}
